{layout name="public/layout" /}
{include file="console/title" /}

<table class="layui-table" lay-data="{height:'full', url:'{:url('Warehouse/Console/category_json')}',id:'idTest'}" lay-filter="demo">
  <thead>
    <tr>
      <th lay-data="{field:'id', width:80,fixed: true}">ID</th>
      <th lay-data="{field:'name', width:200}">名称</th>
      <th lay-data="{field:'description', width:600}">描述</th>
      <th lay-data="{field:'sort', width:80}">排序</th>
      <th lay-data="{fixed: 'right', align:'center', width:150, toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="edit">编辑</a>
</script>
<button class="layui-btn layui-btn-normal btn_add">新增</button>

<script>
layui.use('table', function(){
  var table = layui.table;
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });
  //监听工具条
  table.on('tool(demo)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      layer.open({
        type: 2 //此处以iframe举例
        ,title: '编辑数据'
        ,area: ['500px', '350px']
        ,shade: 0
        ,maxmin: true
        ,content: '/Warehouse/console/category_edit/id/'+data.id+'.html'
      });
    }
  });
  
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
//绑定按钮
$(function(){
    $('.btn_add').on('click',function(){
      layer.open({
        type: 2 //此处以iframe举例
        ,title: '编辑数据'
        ,area: ['500px', '350px']
        ,shade: 0
        ,maxmin: true
        ,content: '/Warehouse/console/category_edit/id/0.html'
      });
    })
})
/*
layui.use(['tree', 'layer'], function(){
  var layer = layui.layer
  $.get("{:url('Warehouse/Console/category_json')}",function(result){
    layui.tree({
      elem: '#tree' //指定元素
      ,target: '_blank' //是否新选项卡打开（比如节点返回href才有效）
      ,click: function(item){ //点击节点回调
        layer.msg('当前节名称：'+ item.name + '<br>全部参数：'+ JSON.stringify(item));
        console.log(item);
      }
      ,nodes: result
    });
  }); 

});
*/
</script>